package Ms

import (
	"database/sql"
	"db2s/global"
	"db2s/go-log/log"
	"db2s/parDef"
	"reflect"
	"time"
)

var WLog *log.Logger

var (
	rowsStaticParameter = map[string]any{
	}
	rowsDynamicParameter = map[string]any{
	}
	metaDynamicParameter = map[string]any{
	}
	metaStaticParameter = map[string]any{
	}
	modeP = map[string]reflect.Value{
		"struct": reflect.ValueOf(StructP),
		"sync":   reflect.ValueOf(syncP),
	}
)
type QueryTable struct {
	Schema              string
	Table               string
	LowerCaseTableNames bool
	ColumnName          []string
	TableColumn         []map[string]string
	HotSqlBeginTime     string
	HostSqlEndTime      string
	DB                  *sql.DB
	LogThreadSeq        int64
	SqlExecStopTime     time.Duration
	MissIndexTablePx    string
	FixRows             int64
	Eas                 global.EncryptionProperties
	Scn                 string
	PartitionName       string
	PartitionId         string
}

type TableMeta struct {
	Schema              string
	Table               string
	LowerCaseTableNames bool
	ColumnName          []string
	TableColumn         []map[string]string
	IndexColumnDataType string
	SqlExecStopTime     time.Duration
	LogThreadSeq        int64
	event               string
	MissIndexTablePx    string
}
type execSqlS struct {
	DB        map[string]*sql.DB
	ShardName string
	Input     global.StartPartConfigInputP
}
type ExecSqlInputS struct {
Ss           any
Event        string
SelectSqlStr string
UpdateSqlStr []string
Expect       string
ShardName    string
}

type (
	newExecSqlS struct {
		DB      *sql.DB
		options Options
	}
	SqlFilter struct {
		WhereSql string
		WhereAdd string
	}
	Object struct {
		Schema    string
		Table     string
		Partition string
	}
	Options struct {
		Scn      string
		StopTime time.Duration
		//Esa                 EncryptionProperties
		WhereSql            string
		WhereAdd            string
		SqlMode             bool
		TablePx             string
		FixRows             int64
		LowerCaseTableNames bool
		SqlLogBin           bool //是否忽略binlog
		RowsLimit           int
		SqlFilter           SqlFilter
	}

	Parameter struct {
		Con     *sql.DB `json:"-"`
		Object  Object  `json:"object"`
		Options Options `json:"options"`
	}
	TableMe struct {
		//Parameter Parameter `json:"parameter"`
	}
	ColumnMe struct {
		Parameter Parameter `json:"parameter"`
	}
	IndexMe struct {
		Parameter Parameter `json:"parameter"`
	}
	PartitionMe struct {
		Parameter Parameter `json:"parameter"`
	}
	ViewMe struct {
		Parameter Parameter `json:"parameter"`
	}
	MViewMe struct {
		Parameter Parameter `json:"parameter"`
	}
	SeqMe struct {}
	JobMe struct {
		Parameter Parameter `json:"parameter"`
	}
	TriggerMe struct {
		Parameter Parameter `json:"parameter"`
	}
	ForeignMe struct {
		Parameter Parameter `json:"parameter"`
	}
	ProcedureMe struct {
		Parameter Parameter `json:"parameter"`
	}
	FuncMe struct {
		Parameter Parameter `json:"parameter"`
	}
	TypeMe struct {
		Parameter Parameter `json:"parameter"`
	}
	PackageMe struct {
		Parameter Parameter `json:"parameter"`
	}
	GolF struct {}
	SumF struct {
		//Parameter Parameter `json:"parameter"`
	}
	RowsF struct {}
	DmlF struct {}
)
type (
	newPartMetaBaseResultS struct {
		PartRule    any `json:"partRule"`
		SubPartRule any `json:"subPartRule"`
		PartMeth    any `json:"partMeth"`
		PartCol     any `json:"partCol"`
		SubPartCol  any `json:"subPartCol"`
	}
	modifyLogoRecord struct {
		Object   string //对象
		Logo     string //改动标识
		OldValue string
		NewValue string
		Reason   string //转换说明
	}
	MetaBaseInitResult struct {
		columnMeta      []columnMeta
		columnMetaMap   []parDef.ColMetaMapS
		indexMeta       []*parDef.IndexColumnMe
		partMe          parDef.PartMetaData
		factor          int
		Character       string
		Collate         string
		Comment         string
		indexColumnUniq map[string]int
		modifyNotNull   []string
		switchRecord    []modifyLogoRecord
	}
)